<?xml version="1.0"?>

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns="default namespace"
	 version="2.1">
	<jsp:directive.page contentType="text/html; charset=UTF-8" />
	<jsp:directive.page isELIgnored="false" />
	<jsp:output 
	omit-xml-declaration="false" 
	doctype-root-element="html"
		doctype-public="-//W3C//DTD XHTML 1.1//EN"
		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd" />
	<jsp:directive.page import="es.albarregas.modelo.Cliente" />
	
	<jsp:directive.page import="es.albarregas.modelo.ModelFacade" />
	<jsp:useBean id="clienteBean" class="es.albarregas.beans.ClienteBean"
		scope="session" />		
	
	<c:out value="${param.nombre}"></c:out>
	<c:forEach var="campos" items="${param}">
		<c:if test="${fn:length(campos.value)==0}">
			<c:set var="error" value="1" />
		</c:if>
	</c:forEach>
	
	<!--<jsp:setProperty name="usuarioBean" property="*" />-->
	<jsp:setProperty name="clienteBean" property="*" />
	<c:choose>
		<c:when test="${error==1}">
			<jsp:forward page="ForRegistro.jsp">
				<jsp:param value="1" name="error" />
			</jsp:forward>
		</c:when>
		<c:otherwise>
			<jsp:scriptlet>				
				System.out.println("Hemos entrado en CtrlRegistro.jsp");
				System.out.println("Hemos guardado en clienteBean ");
				System.out.println("Nombre-->"+clienteBean.getNombre());
				System.out.println("Apellido-->"+clienteBean.getApellidos());
				System.out.println("Dni-->"+clienteBean.getNifNie());				
				System.out.println("email-->"+clienteBean.getEmail());
				System.out.println("telefono-->"+clienteBean.getTelefono());
				System.out.println("clave-->"+clienteBean.getClave());
				Cliente cliente = ModelFacade.crearCliente(clienteBean, true);
				request.setAttribute("cliente", cliente);				
			</jsp:scriptlet>
			<c:choose>
			
				<c:when test="${cliente==null}">
					<jsp:forward page="ErrOperacion.jsp">
						<jsp:param value="1" name="lugar" />
					</jsp:forward>
				</c:when>
				<c:otherwise>					
					<jsp:scriptlet>				
						System.out.println("Cliente distinto de null");						
					</jsp:scriptlet>					
					<jsp:forward page="VisOk.jsp">
						<jsp:param value="1" name="lugar" />
					</jsp:forward>					
				</c:otherwise>
			</c:choose>
		</c:otherwise>
	</c:choose>
</jsp:root>